<template>
  <!-- 申请弹窗 -->
  <a-modal
    :title="title"
    :width="width"
    :visible="visible"
    :okButtonProps="{ class: { 'jee-hidden': disableSubmit } }"
    @ok="handleOk"
    @cancel="handleCancel"
  >
    <MaterialForm
      ref="modalForm"
      :editable="editable"
      :dataId="dataId"
      v-model="formData"
      @ok="visible = false"
    ></MaterialForm>
  </a-modal>
</template>

<script>
import { setMaterial } from '@/api/api'
import MaterialForm from './MaterialForm'
export default {
  name: 'MaterialModal',
  components: {
    MaterialForm,
  },
  data() {
    return {
      title: '',
      width: 800,
      visible: false,
      disableSubmit: false,
      editable: false,
      formData: {},
      workflowModel: {
        operation: 'start',
      },
      dataId: '',
      successTxt: '',
    }
  },
  methods: {
    add() {
      this.edit(
        {
          actStatus: 10,
        },
        '添加成功'
      )
    },
    create() {
      this.edit(
        {
          workflowModel: {
            operation: 'start',
          },
        },
        '申请成功'
      )
    },
    edit(record, successTxt) {
      // this.successTxt = successTxt||'编辑成功'
      this.visible = true
      // this.formData = record
      this.$nextTick(() => {
        this.$refs.modalForm.edit(record)
      })
    },
    review(record) {
      this.title = '查看'
      this.visible = true
      this.editable = true
      console.log(this.editable);
      // this.dataId =record.id
      // this.formData = record

      this.$nextTick(() => {
        this.$refs.modalForm.open(record)
      })
    },
    close() {
      this.$emit('close')
      this.title = ''
      this.editable = true
      this.formData = {}
      this.disableSubmit = false
      this.visible = false
    },
    handleOk() {
      this.$refs.modalForm.submitForm().then((res) => {
        this.$emit('ok')
        this.visible = false
      })
      // let that =this
      // this.$refs.modalForm.form.validateFields((err, values) => {
      //     if (!err) {
      //         setMaterial(Object.assign({},this.formData, values)).then(res=>{
      //             if(res.success){
      //                 that.$notification.success({
      //                     message: that.successTxt,
      //                 });
      //                 that.$emit('ok');
      //                 that.visible = false;
      //             }else{
      //                 that.$notification.error({
      //                     message: res.message
      //                 })
      //             }
      //         })
      //     }

      // })
    },
    handleCancel() {
      this.close()
    },
  },
}
</script>

<style>
</style>